<?php
#基础函数
include_once('_path.php');

if (BENCHMARK) {
	require_once(_CONST_LOCAL_INCLUDE_PATH.'/Benchmark/Timer.php');
	$timer = new Benchmark_Timer();
	$timer->start();
}

#db
include_once(_CONST_LOCAL_INCLUDE_PATH."database.class.php");
$database = new Database($db_vars);

if ($db_slave_vars['hostname'] != '') {
	$slave = new Database($db_slave_vars);
} else {
	$slave =& $database;
}

#通用函数
include_once(_CONST_LOCAL_INCLUDE_PATH."common.php");

if (BENCHMARK) $timer->setMarker('init');

#登录权限
check_loggedin();

#用户信息
include_once(_CONST_LOCAL_INCLUDE_PATH."session.include.php");

if (BENCHMARK) $timer->setMarker('auth');

#处理上一步骤
if(!isset($_SESSION['step_3'])){	
	$token = $_POST['token'];
	if(empty($token) || $token != $_SESSION['token']){
		//exit("Access Exit!");
		header("Location:"._CONST_WEB_URL."flow-1.php");
		exit;
	}
}
	
if (isset($_POST['step']) && $_POST['step'] == 'do') {
	#校验
	verify_field("myimg", "GImg", "empty");
	verify_field("myimg", "GImg", "custom", "/^(http:\/\/).+(jpg|jpeg).*$/i");
	if (count($error_strs)) {
		exit("Error Pargram Exit!");
	}

	$myimg = trim($_POST['myimg']);

	$_SESSION['step_2'] = array(
		'myimg' => $myimg,
	);
}
#初始化第二步
$token = md5(uniqid().time());
$_SESSION['token'] = $token;

#cache lite
include_once(_CONST_LOCAL_INCLUDE_PATH.'Cache/Lite.php');
include_once(_CONST_LOCAL_INCLUDE_PATH.'Cache/Lite/Output.php');

$cache = new Cache_Lite_Output();

#用于meta的keywords标签
$keywords = "";
#用于meta的Description标签
$description = "";
#用于mete的http-equiv标签
$referrer = "";
#用于meta的title标签
$title = "添加一段描述 - Votings";
#用于获取针对本页的css样式
$css = array();
#用于获取针对本页的js
$js = array();
#用于获取针对head的其他标签
$links = array();
#用于控制那个主菜单为
$o = "";

$ads = array();

$post_code =<<<HTML
HTML;

if (BENCHMARK) $timer->setMarker('proc');

//if ($user['loggedin'] < 1)
//	cache_header(900);

no_cache_header();

#header
include_once(_CONST_LOCAL_LAYOUT_PATH."_header.php");
?>
<?php
if(isset($_SESSION['step_2'])){
?>
	<script>
	$(function(){
		$("#desc").val('<?php echo $_SESSION['step_3']['desc']?>');
	});
    </script>
<?php
}
?>
<div id="main">
<form name="step3" id="step-3" action="flow-4.php" method="post">
<input name="token" id="token" type="hidden" value="<?php echo $token;?>">
<input name="step" id="step" type="hidden" value="3">
	<div class="box">
		<ul class="flow clearfix f3">
			<li>1、选择商品图片</li>
			<li>2、选择自己的照片</li>
			<li class="cur">3、添加一段描述</li>
			<li>4、发布投票</li>
		</ul>
		<div class="box-header"><h1>为投票添加一段描述</h1></div>
		<div class="input-wrap clearfix">
			<div class="input-wrap clearfix">
				<label for="">描述</label>
				<textarea id="desc" name="desc" class="add-voting-des" onfocus = "if(this.value=='Some words about why would you like to buy this item or why you feel uncertain about it.'){this.value='';}" onblur = "if(this.value==''){this.value='Some words about why would you like to buy this item or why you feel uncertain about it.'}"  >Some words about why would you like to buy this item or why you feel uncertain about it.</textarea>
			</div>
			<div class="box-header"></div>
			<div class="next-step"><input type="button" name="previous-step" class="previous" value="" onclick = "window.location.href='<?php echo _CONST_WEB_URL . 'flow-2.php'?>';" /><input type="button" name="next-step" id="next-step" class="next"  value=""  onclick="vote.checkForm3();"/></div>
		</div>
		
	</div>
</form>	
</div>
<!--main end-->
<?php
//footer
include_once (_CONST_LOCAL_LAYOUT_PATH."_footer.php");

if (BENCHMARK) $timer->setMarker('page');

if (BENCHMARK) {
	echo "<!-- init: ".$timer->timeElapsed('Start', 'init')." -->\n";
	echo "<!-- auth: ".$timer->timeElapsed('init', 'auth')." -->\n";
	echo "<!-- proc: ".$timer->timeElapsed('auth', 'proc')." -->\n";
	echo "<!-- page: ".$timer->timeElapsed('proc', 'page')." -->\n";
	echo "<!-- total: ".$timer->timeElapsed('Start', 'Stop')." -->\n";
}

?>
